﻿@{
    Layout = null;
}
@model System.Data.DataTable
<!DOCTYPE html>

<html>
<head>
    <title>Test_Query</title>
</head>
<body>
    @Html.DevExpress().GridView(
             ss =>
             {
                 ss.Name = "gvEditing";
                 ss.KeyFieldName = "NSRDZDAH";
                 ss.CallbackRouteValues = new { Controller = "QueryAllowanceForecast", Action = "AllowanceForecastPartial" };
                 ss.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                 ss.SettingsPager.PageSize = 100;

                 ss.Columns.Add("FEnterprisePropName", "企业性质").GroupIndex = 1;
                 ss.Columns.Add("FFinancePropName", "资金性质");
                 ss.Columns.Add("NSRSBH", "纳税人识别号").GroupIndex = 2;
                 ss.Columns.Add("NSRBM", "纳税人编码");
                 ss.Columns.Add("NSRMC", "纳税人名称");
                 ss.Columns.Add("FAmount", "营改增补助金额");
                 ss.Columns.Add("base", "基数");
                 foreach (var t in ViewBag.TaxClassAllowance as List<EnterpriseFund.Model.TaxClassAllowance>)
                 {
                     ss.Columns.Add(t.FTaxClassAllowanceNo, t.FTaxClassAllowanceName);
                     ss.Columns.Add("FRuleFormula_" + t.FTaxClassAllowanceNo, "符合条件");
                     ss.Columns.Add("FComputeExpression_" + t.FTaxClassAllowanceNo, "ComputeExpression");
                     ss.Columns.Add("FComputeValue_" + t.FTaxClassAllowanceNo, "可补贴金额");
                 }
                 

                 ss.Settings.ShowGroupPanel = true;

                 ss.SettingsBehavior.AllowSort = true;
                 ss.SettingsBehavior.AllowDragDrop = false;
                 ss.SettingsBehavior.AllowSelectByRowClick = false;
                 ss.SettingsBehavior.AllowClientEventsOnLoad = false;
                 ss.SettingsBehavior.AllowFocusedRow = true;
                 ss.SettingsBehavior.AutoExpandAllGroups = true;
                 ss.SettingsLoadingPanel.Text = "数据读取中...";

                 ss.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";
                 ss.ClientSideEvents.EndCallback = "function(){Compute()}";
                 ss.CommandColumn.Visible = false;

                 ss.PageIndexChanged = (sender, e) =>
                 {
                     ASPxGridView grid = (ASPxGridView)sender;
                     grid.Selection.UnselectAll();
                 };

             }).Bind(Model).GetHtml()
</body>
</html>

<script>
    function Compute() {

        var tableObj = document.getElementById("gvEditing_DXMainTable");

        var computeExpressionColumnIndex = new Array();

        for (var j = 0; j < tableObj.rows[0].cells.length; j++) {
            var columnName = tableObj.rows[0].cells[j].innerText.toLowerCase();
            if (columnName.indexOf("computeexpression") >= 0) {
                computeExpressionColumnIndex.push(j);
            }
        }

        for (var i = 1; i < tableObj.rows.length; i++) {
            for (var j = 1; j < computeExpressionColumnIndex.length; j++) {
                var expressionCell = tableObj.rows[i].cells[computeExpressionColumnIndex[j]];
                var valueCell = tableObj.rows[i].cells[computeExpressionColumnIndex[j] - 1];
                if (expressionCell.innerText != "")
                    valueCell.innerText = eval(expressionCell.innerText).toFixed(2);
            }
        }

    }

    //脚本计算时间统计
    document.writeln(new Date());
    document.write(new Date().getMilliseconds());
    document.write("<br />");
    Compute();
    document.writeln(new Date());
    document.write(new Date().getMilliseconds());
</script>